package com.diko.controller;

import com.diko.commonUtils.R;
import com.diko.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author Emma Li
 * @date 2020/10/9 - 10:04
 */
@Api(description = "阿里云视频点播微服务")
//@CrossOrigin
@RestController
@RequestMapping("/eduvod/video")
public class VideoAdminController {
    @Autowired
    private VideoService videoService;

    @PostMapping("upload")
    public R uploadVideo(
            @ApiParam(name="file",value = "文件",required = true)
            @RequestParam("file")MultipartFile file
            )throws Exception{
        String videoId = videoService.uploadVideo(file);
        return R.ok().message("视频上传成功").data("videoId",videoId);
    }

    @DeleteMapping("/delete/{videoId}")
    public R removeVideo(@ApiParam(name="videoId",value = "云端视频id",required = true)
                         @PathVariable String videoId){
        videoService.removeVideo(videoId);
        return R.ok().message("视频删除成功");
    }

    /*
    * 批量删除视频
    * */
    @DeleteMapping("delete-batch")
    public R removeVideoList(
            @ApiParam(name="videoIdList",value = "云端视频id",required = true)
            @RequestParam("videoIdList")List<String> videoIdList)
    {
        videoService.removeVideoList(videoIdList);
        return R.ok().message("视频删除成功");
    }
}
